home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / SCSI Samples 1.0 / SCSI Async Sample 06⁄15 ƒ / Src / SCSIDefinitions.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-16  |  14.1 KB  |  447 lines  |  [TEXT/KAHL]

  1. /*                            SCSIDefinitions.h                            */
  2. /*
  3.  * Scsi-specific definitions.
  4.  */
  5. #ifndef __SCSIDefinitions__
  6. #define __SCSIDefinitions__
  7.  
  8. /*
  9.  * Include the O.S. files in a specific order to make sure that we have
  10.  * a definition for the _SCSIAtomic trap.
  11.  */
  12. #include <Traps.h>
  13. #ifndef _SCSIAtomic
  14. #define _SCSIAtomic    0xA089
  15. #endif
  16. /*
  17.  * Note that this uses a later version of <Scsi.h> than is available in
  18.  * the public headers.
  19.  */
  20. #include "SCSI.h"
  21.  
  22. typedef unsigned char    byte;
  23. #ifndef NULL
  24. #define NULL        0
  25. #endif
  26.  
  27. /*
  28.  * The 6-byte commands are used for most simple
  29.  * I/O requests.
  30.  */
  31. struct SCSI_6_Byte_Command {            /* Six-byte command            */
  32.     byte        opcode;                    /*  0                        */
  33.     byte        lbn3;                    /*  1 lbn in low 5            */
  34.     byte        lbn2;                    /*  2                        */
  35.     byte        lbn1;                    /*  3                        */
  36.     byte        len;                    /*  4                        */
  37.     byte        ctrl;                    /*  5                        */
  38. };
  39. typedef struct SCSI_6_Byte_Command SCSI_6_Byte_Command;
  40.  
  41. struct SCSI_10_Byte_Command {            /* Ten-byte command            */
  42.     byte        opcode;                    /*  0                        */
  43.     byte        lun;                    /*  1                        */
  44.     byte        lbn4;                    /*  2                        */
  45.     byte        lbn3;                    /*  3                        */
  46.     byte        lbn2;                    /*  4                        */
  47.     byte        lbn1;                    /*  5                        */
  48.     byte        pad;                    /*  6                        */
  49.     byte        len2;                    /*  7                        */
  50.     byte        len1;                    /*  8                        */
  51.     byte        ctrl;                    /*  9                        */
  52. };
  53. typedef struct SCSI_10_Byte_Command SCSI_10_Byte_Command;
  54.  
  55. struct SCSI_12_Byte_Command {            /* Twelve-byte command        */
  56.     byte        opcode;                    /*  0                        */
  57.     byte        lun;                    /*  1                        */
  58.     byte        lbn4;                    /*  2                        */
  59.     byte        lbn3;                    /*  3                        */
  60.     byte        lbn2;                    /*  4                        */
  61.     byte        lbn1;                    /*  5                        */
  62.     byte        len4;                    /*  6                        */
  63.     byte        len3;                    /*  7                        */
  64.     byte        len2;                    /*  8                        */
  65.     byte        len1;                    /*  9                        */
  66.     byte        pad;                    /* 10                        */
  67.     byte        ctrl;                    /* 11                        */
  68. };
  69. typedef struct SCSI_12_Byte_Command SCSI_12_Byte_Command;
  70.  
  71. /*
  72.  * This union defines all scsi commands.
  73.  */
  74. union SCSI_Command {
  75.     SCSI_6_Byte_Command        scsi6;
  76.     SCSI_10_Byte_Command    scsi10;
  77.     SCSI_12_Byte_Command    scsi12;
  78.     byte                    scsi[12];
  79. };
  80. typedef union SCSI_Command SCSI_Command, *SCSI_CommandPtr;
  81.  
  82. /*
  83.  * Returned by a read-capacity command.
  84.  */
  85. struct SCSI_Capacity_Data {
  86.     byte        lbn4;                /* Number                    */
  87.     byte        lbn3;                /*  of                        */
  88.     byte        lbn2;                /*   logical                */
  89.     byte        lbn1;                /*    blocks                */
  90.     byte        len4;                /* Length                    */
  91.     byte        len3;                /*  of each                    */
  92.     byte        len2;                /*   logical block            */
  93.     byte        len1;                /*    in bytes                */
  94. };
  95. typedef struct SCSI_Capacity_Data SCSI_Capacity_Data;
  96.  
  97. struct SCSI_Inquiry_Data {            /* Inquiry returns this        */
  98.     byte        devType;            /*  0 Device type,            */
  99.     byte        devTypeMod;            /*  1 Device type modifier    */
  100.     byte        version;            /*  2 ISO/ECMA/ANSI version    */
  101.     byte        format;                /*  3 Response data format    */
  102.     byte        length;                /*  4 Additional Length        */
  103.     byte        reserved5;            /*  5 Reserved                */
  104.     byte        reserved6;            /*  6 Reserved                */
  105.     byte        flags;                /*  7 Capability flags        */
  106.     byte        vendor[8];            /*  8-15 Vendor-specific    */
  107.     byte        product[16];        /* 16-31 Product id            */
  108.     byte        revision[4];        /* 32-35 Product revision    */
  109.     byte        vendorSpecific[20]; /* 36-55 Vendor stuff        */
  110.     byte        moreReserved[40];    /* 56-95 Reserved            */
  111. };
  112. typedef struct SCSI_Inquiry_Data SCSI_Inquiry_Data;
  113.  
  114. /*
  115.  * This bit may be set in devTypeMod
  116.  */
  117. enum {
  118.     kScsiInquiryRMB = 0x80            /* Removable medium    if set    */
  119. };
  120. /*
  121.  * These bits may be set in flags
  122.  */
  123. enum {
  124.     kScsiInquiryRelAdr    = 0x80,        /* Has relative addressing    */
  125.     kScsiInquiryWBus32    = 0x40,        /* Wide (32-bit) transfers    */
  126.     kScsiInquiryWBus16    = 0x20,        /* Wide (16-bit) transfers    */
  127.     kScsiInquirySync    = 0x10,        /* Synchronous transfers    */
  128.     kScsiInquiryLinked    = 0x08,        /* Linked commands ok        */
  129.     kScsiInquiryReserved = 0x04,
  130.     kScsiInquiryCmdQue    = 0x02,        /* Tagged cmd queuing ok    */
  131.     kScsiInquirySftRe    = 0x01        /* Soft reset alternative    */
  132. };
  133.  
  134. /*
  135.  * These are the device types that SCSI knows about.
  136.  */    
  137. enum {
  138.     kScsiDevTypeDirect                    = 0,
  139.     kScsiDevTypeSequential,
  140.     kScsiDevTypePrinter,
  141.     kScsiDevTypeProcessor,
  142.     kScsiDevTypeWorm,                        /* Write-once, read multiple        */
  143.     kScsiDevTypeCDROM,
  144.     kScsiDevTypeScanner,
  145.     kScsiDevTypeOptical,
  146.     kScsiDevTypeChanger,
  147.     kScsiDevTypeComm,
  148.     kScsiDevTypeGraphicArts0A,
  149.     kScsiDevTypeGraphicArts0B,
  150.     kScsiDevTypeFirstReserved,                /* Start of reserved sequence        */
  151.     kScsiDevTypeUnknownOrMissing        = 0x1F,
  152.     kScsiDevTypeMask                    = 0x1F
  153. };
  154. /*
  155.  * These are device type modifiers. We need them to distinguish between "unknown"
  156.  * and "missing" devices.
  157.  */
  158. enum {
  159.     kScsiDevTypeQualifierConnected        = 0x00,    /* Exists and is connected        */
  160.     kScsiDevTypeQualifierNotConnected    = 0x20,    /* Logical unit exists            */
  161.     kScsiDevTypeQualifierReserved        = 0x40,
  162.     kScsiDevTypeQualifierMissing        = 0x60,    /* No such logical unit            */
  163.     kScsiDevTypeQualifierVendorSpecific    = 0x80,    /* Other bits are unspecified    */
  164.     kScsiDevTypeQualifierMask            = 0xE0
  165. };
  166. #define kScsiDevTypeMissing    \
  167.     (kScsiDevTypeUnknownOrMissing | kScsiDevTypeQualifierMissing)
  168.  
  169. /*
  170.  * This is the data that is returned after a GetExtendedStatus
  171.  * request. The errorCode gives a general indication of the error,
  172.  * which may be qualified by the additionalSenseCode and
  173.  * additionalSenseQualifier fields. These may be device (vendor)
  174.  * specific values, however. The info[] field contains additional
  175.  * information. For a media error, it contains the failing
  176.  * logical block number (most-significant byte first).
  177.  */
  178. struct SCSI_Sense_Data {        /* Request Sense result            */
  179.     byte        errorCode;        /*  0    Class code, valid lbn    */
  180.     byte        segmentNumber;    /*  1    Segment number            */
  181.     byte        senseKey;        /*  2    Sense key and flags        */
  182.     byte        info[4];
  183.     byte        additionalSenseLength;
  184.     byte        reservedForCopy[4];
  185.     byte        additionalSenseCode;
  186.     byte        additionalSenseQualifier;    
  187.     byte        fruCode;        /* Field replacable unit code    */
  188.     byte        senseKeySpecific[2];
  189.     byte        additional[101];
  190. };
  191. typedef struct SCSI_Sense_Data SCSI_Sense_Data;
  192. /*
  193.  * The high-bit of errorCode signals whether there is a logical
  194.  * block. The low value signals whether there is a valid sense
  195.  */
  196. #define kScsiSenseHasLBN            0x80    /* Logical block number set    */
  197. #define kScsiSenseInfoValid            0x70    /* Is sense key valid?        */
  198. #define kScsiSenseInfoMask            0x70    /* Mask for sense info        */
  199. /*
  200.  * These bits may be set in the sense key
  201.  */
  202. #define kScsiSenseKeyMask            0x0F
  203. #define kScsiSenseILI                0x20    /* Illegal logical Length    */
  204. #define kScsiSenseEOM                0x40    /* End of media                */
  205. #define kScsiSenseFileMark            0x80    /* End of file mark            */
  206.  
  207. /*
  208.  * SCSI sense codes. (Returned after request sense).
  209.  */
  210. #define     kScsiSenseNone                0x00    /* No error                    */
  211. #define     kScsiSenseRecoveredErr        0x01    /* Warning                    */
  212. #define     kScsiSenseNotReady            0x02    /* Device not ready            */
  213. #define     kScsiSenseMediumErr        0x03    /* Device medium error        */
  214. #define     kScsiSenseHardwareErr        0x04    /* Device hardware error    */
  215. #define     kScsiSenseIllegalReq        0x05    /* Illegal request for dev.    */
  216. #define     kScsiSenseUnitAtn            0x06    /* Unit attention (not err)    */
  217. #define     kScsiSenseDataProtect        0x07    /* Data protection            */
  218. #define     kScsiSenseBlankCheck        0x08    /* Tape-specific error        */
  219. #define     kScsiSenseVendorSpecific    0x09    /* Vendor-specific error    */
  220. #define     kScsiSenseCopyAborted        0x0a    /* Copy request cancelled    */
  221. #define     kScsiSenseAbortedCmd        0x0b    /* Initiator aborted cmd.    */
  222. #define     kScsiSenseEqual            0x0c    /* Comparison equal            */
  223. #define     kScsiSenseVolumeOverflow    0x0d    /* Write past end mark        */
  224. #define     kScsiSenseMiscompare        0x0e    /* Comparison failed        */
  225. #define     kScsiSenseCurrentErr        0x70
  226. #define     kScsiSenseDeferredErr        0x71
  227.  
  228. /*
  229.  * Mode sense parameter header
  230.  */
  231. struct SCSI_ModeParamHeader {
  232.     byte        modeDataLength;
  233.     byte        mediumType;
  234.     byte        deviceSpecific;
  235.     byte        blockDescriptorLength;
  236. };
  237. typedef struct SCSI_ModeParamHeader SCSI_ModeParamHeader;
  238.  
  239. struct SCSI_ModeParamBlockDescriptor {
  240.     byte        densityCode;
  241.     byte        numberOfBlocks[3];
  242.     byte        reserved;
  243.     byte        blockLength[3];
  244. };
  245. typedef struct SCSI_ModeParamBlockDescriptor SCSI_ModeParamBlockDescriptor;
  246.  
  247. union SCSI_ModeParamPage {
  248.     byte        data[1];
  249.     struct {
  250.         byte    code;
  251.         byte    length;
  252.     } page;
  253. };
  254. typedef union SCSI_ModeParamPage SCSI_ModeParamPage;
  255.  
  256. /*
  257.  * LogSense parameter header
  258.  */
  259. struct SCSI_LogSenseParamHeader {
  260.     byte        pageCode;
  261.     byte        reserved;
  262.     byte        pageLength[2];
  263. };
  264. typedef struct SCSI_LogSenseParamHeader SCSI_LogSenseParamHeader;
  265.  
  266. /*
  267.  * Log parameter pages are variable-length with a fixed length header.
  268.  */
  269. union SCSI_LogSenseParamPage {
  270.     byte        data[1];
  271.     struct {
  272.         byte    parameterCode[2];
  273.         byte    flags;
  274.         byte    parameterLength;
  275.     } page;
  276. };
  277. typedef union SCSI_LogSenseParamPage SCSI_LogSenseParamPage;
  278.  
  279. /*
  280.  * SCSI command status (from status phase)
  281.  */
  282. #define     kScsiStatusGood            0x00    /* Normal completion        */
  283. #define     kScsiStatusCheckCondition    0x02    /* Need GetExtendedStatus    */
  284. #define     kScsiStatusConditionMet    0x04
  285. #define     kScsiStatusBusy            0x08    /* Device busy (self-test?)    */
  286. #define     kScsiStatusIntermediate    0x10    /* Intermediate status        */
  287. #define     kScsiStatusResConflict        0x18    /* Reservation conflict        */
  288. #define     kScsiStatusQueueFull        0x28    /* Target can't do command    */
  289. #define     kScsiStatusReservedMask    0x3e    /* Vendor specific?            */
  290.  
  291. /*
  292.  * SCSI command codes. Commands defined as ...6, ...10, ...12, are
  293.  * six-byte, ten-byte, and twelve-byte variants of the indicated command.
  294.  */
  295. /*
  296.  * These commands are supported for all devices.
  297.  */
  298. #define kScsiCmdChangeDefinition    0x40
  299. #define kScsiCmdCompare                0x39
  300. #define kScsiCmdCopy                0x18
  301. #define kScsiCmdCopyAndVerify        0x3a
  302. #define kScsiCmdInquiry                0x12
  303. #define kScsiCmdLogSelect            0x4c
  304. #define kScsiCmdLogSense            0x4d
  305. #define kScsiCmdModeSelect12        0x55
  306. #define kScsiCmdModeSelect6            0x15
  307. #define kScsiCmdModeSense12            0x5a
  308. #define kScsiCmdModeSense6            0x1a
  309. #define kScsiCmdReadBuffer            0x3c
  310. #define kScsiCmdRecvDiagResult        0x1c
  311. #define kScsiCmdRequestSense        0x03
  312. #define kScsiCmdSendDiagnostic        0x1d
  313. #define kScsiCmdTestUnitReady        0x00
  314. #define kScsiCmdWriteBuffer            0x3b
  315.  
  316. /*
  317.  * These commands are supported by direct-access devices only.
  318.  */
  319. #define kScsiCmdFormatUnit            0x04
  320. #define kSCSICmdCopy                0x18
  321. #define kSCSICmdCopyAndVerify        0x3a
  322. #define kScsiCmdLockUnlockCache        0x36
  323. #define kScsiCmdPrefetch            0x34
  324. #define kScsiCmdPreventAllowRemoval    0x1e
  325. #define kScsiCmdRead6                0x08
  326. #define kScsiCmdRead10                0x28
  327. #define kScsiCmdReadCapacity        0x25
  328. #define kScsiCmdReadDefectData        0x37
  329. #define kScsiCmdReadLong            0x3e
  330. #define kScsiCmdReassignBlocks        0x07
  331. #define kScsiCmdRelease                0x17
  332. #define kScsiCmdReserve                0x16
  333. #define kScsiCmdRezeroUnit            0x01
  334. #define kScsiCmdSearchDataEql        0x31
  335. #define kScsiCmdSearchDataHigh        0x30
  336. #define kScsiCmdSearchDataLow        0x32
  337. #define kScsiCmdSeek6                0x0b
  338. #define kScsiCmdSeek10                0x2b
  339. #define kScsiCmdSetLimits            0x33
  340. #define kScsiCmdStartStopUnit        0x1b
  341. #define kScsiCmdSynchronizeCache    0x35
  342. #define kScsiCmdVerify                0x2f
  343. #define kScsiCmdWrite6                0x0a
  344. #define kScsiCmdWrite10                0x2a
  345. #define kScsiCmdWriteAndVerify        0x2e
  346. #define kScsiCmdWriteLong            0x3f
  347. #define kScsiCmdWriteSame            0x41
  348.  
  349. /*
  350.  * These commands are supported by sequential devices.
  351.  */
  352. #define kScsiCmdRewind                0x01
  353. #define kScsiCmdWriteFilemarks        0x10
  354. #define kScsiCmdSpace                0x11
  355. #define kScsiCmdLoadUnload            0x1B
  356. /*
  357.  * ANSI SCSI-II for CD-ROM devices.
  358.  */
  359. #define kScsiCmdReadCDTableOfContents    0x43
  360.  
  361. /*
  362.  * Message codes (for Msg In and Msg Out phases). The Macintosh
  363.  * SCSI Manager can't really deal with these.
  364.  */
  365. #define kScsiMsgAbort                0x06
  366. #define kScsiMsgAbortTag            0x0d
  367. #define kScsiMsgBusDeviceReset        0x0c
  368. #define kScsiMsgClearQueue            0x0e
  369. #define kScsiMsgCmdComplete            0x00
  370. #define kScsiMsgDisconnect            0x04
  371. #define kScsiMsgIdentify            0x80
  372. #define kScsiMsgIgnoreWideResdue    0x23
  373. #define kScsiMsgInitiateRecovery    0x0f
  374. #define kScsiMsgInitiatorDetectedErr 0x05
  375. #define kScsiMsgLinkedCmdComplete    0x0a
  376. #define kScsiMsgLinkedCmdCompleteFlag 0x0b
  377. #define kScsiMsgParityErr            0x09
  378. #define kScsiMsgRejectMsg            0x07
  379. #define kScsiMsgModifyDataPtr        0x00 /* Extended msg        */
  380. #define kScsiMsgNop                    0x08
  381. #define kScsiMsgHeadOfQueueTag        0x21 /* Two byte msg        */
  382. #define kScsiMsgOrderedQueueTag        0x22 /* Two byte msg        */
  383. #define kScsiMsgSimpleQueueTag        0x20 /* Two byte msg        */
  384. #define kScsiMsgReleaseRecovery        0x10
  385. #define kScsiMsgRestorePointers        0x03
  386. #define kScsiMsgSaveDataPointers    0x02
  387. #define kScsiMsgSyncXferReq            0x01 /* Extended msg        */
  388. #define kScsiMsgWideDataXferReq        0x03 /* Extended msg        */
  389. #define kScsiMsgTerminateIOP        0x11
  390. #define kScsiMsgExtended            0x01
  391.  
  392. #define kScsiMsgTwoByte                0x20
  393. #define kScsiMsgTwoByteMin            0x20
  394. #define kScsiMsgTwoByteMax            0x2f
  395.  
  396. /*
  397.  * Default timeout times for SCSI commands.
  398.  */
  399. #define kScsiNormalCompletionTime    (30L)            /* 1/2 second                */
  400. /*
  401.  * Dratted DAT tape.
  402.  */
  403. #define kScsiDATCompletionTime        (60L * 60L);    /* One minute                */
  404. /*
  405.  * Yes, we do allow 90 seconds for spin-up of those dratted tape drives.
  406.  */
  407. #define kScsiSpinUpCompletionTime    (60L * 90L)
  408.  
  409. /*
  410.  * The NCR Bits, as returned by ScsiStat are only useful for maintenence
  411.  * and testing. Only the following bits are valid in the current
  412.  * implementation of the SCSI Manager. There is no guarantee that the
  413.  * bits are accessable, or useful, in future SCSI implementations.
  414.  *
  415.  * Using these bits, the following implications can be drawn:
  416.  *    kScsiStatBSY        Bus is busy. (On systems with multiple busses,
  417.  *                        there is no indication which bus is busy.)
  418.  *    kScsiStatREQ        Bus is busy. There is no way to determine whether
  419.  *                        the target has changed phase or has set REQ.
  420.  *    Bus Phase            If kScsiStatREQ and kSCSIStatBSY are set, the
  421.  *                        phase bits will indicate the current bus phase.
  422.  */
  423. #define    kScsiStatBSY            bit6    /* Bus Busy                    */
  424. #define    kScsiStatREQ            bit5    /* Set if Bus Busy            */
  425. #define    kScsiStatMSG            bit4    /* MSG phase bit            */
  426. #define    kScsiStatCD                bit3    /* C/D phase bit            */
  427. #define    kScsiStatIO                bit2    /* I/O phase bit            */
  428.  
  429.  
  430. #define    kScsiPhaseMask    (kScsiStatMSG | kScsiStatCD | kScsiStatIO)
  431. #define kScsiPhaseShift    (2)
  432. #define    ScsiBusPhase(x) (((x) & kScsiPhaseMask) >> kScsiPhaseShift)
  433.  
  434. /*
  435.  * The phases are defined by a combination of bus lines.
  436.  * Note: these values have been shifted already.
  437.  * Other values are undefined.
  438.  */
  439. #define kScsiPhaseDATO        0    /* Data output (host -> device)                    */
  440. #define kScsiPhaseDATI        1    /* Data input  (device -> host)                    */
  441. #define kScsiPhaseCMD        2    /* Command                                        */
  442. #define kScsiPhaseSTS        3    /* Status                                        */
  443. #define kScsiPhaseMSGO        6    /* Message output                                */
  444. #define kScsiPhaseMSGI        7    /* Message input                                */
  445.  
  446. #endif /* __MacSCSICommand__ */
  447.